home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
57674
/
57674.xpi
/
chrome
/
curss.jar
/
content
/
cursitesearch.js
next >
Wrap
Text File
|
2010-01-03
|
5KB
|
157 lines
const curss_prefserv = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
const wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
var curss = {
init: function()
{
var menu = document.getElementById("contentAreaContextMenu");
menu.addEventListener("popupshowing", curss.onPopupShowing, false);
var buttons = document.getElementById("curss-Buttons");
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var item = document.createElementNS(XUL_NS, "toolbarbutton");
item.setAttribute("label", "Search");
item.setAttribute("style", "cursor: pointer;list-style-image: url(chrome://cursitesearch/skin/search.ico)");
item.setAttribute("oncommand", "curss.curss_Search();");
item.setAttribute("tooltiptext", "Search");
item.setAttribute("id", "curss_search");
item.setAttribute("hidden", false);
buttons.appendChild(item);
},
onPopupShowing: function ()
{
var focusedWindow = document.commandDispatcher.focusedWindow;
var searchStr = focusedWindow.getSelection();
var item = document.getElementById("context-curss");
if (searchStr != '')
item.setAttribute("label", "Add \"" + searchStr + "\" to CurrentSiteSearch box");
},
curss_Search: function()
{
var isEmpty = false;
var searchTermsBox = document.getElementById("curss-SearchTerms");
var searchTerms = this.curss_TrimString(searchTermsBox.value);
if(searchTerms.length == 0)
isEmpty = true;
else
searchTerms = this.curss_ConvertTermsToURI(searchTerms);
var mainWindow = wm.getMostRecentWindow("navigator:browser");
var tabbrowser = mainWindow.gBrowser;
var hostparam = "";
try {
hostparam = "site:" + tabbrowser.currentURI.host + " ";
} catch (e) { // no site is opened on in a tab
};
if (hostparam == "site:www.google.com ") {
hostparam = "";
}
var URL = "http://www.google.com/custom?client=pub-6701758236670253&channel=7031513415&cof=FORID%3A13%3BAH%3Aleft%3BCX%3ACurrent%2520site%2520search%3BL%3Ahttp%3A%2F%2Fwww.google.com%2Fintl%2Fen%2Fimages%2Flogos%2Fcustom_search_logo_sm.gif%3BLH%3A30%3BLP%3A1%3BLC%3A%230000ff%3BVLC%3A%23663399%3BDIV%3A%23336699%3B&adkw=AELymgXeH9s5blLP0YgClhe0RUurpYq-9kcTIow3hh4O2dXfNAPIqFHGA_jHQBZ6bpes-4izs4RvttGUHMhCIQx3UIkSFMfRK9MvCZazG-2WLuLgYCF-ywY&btnG=Search&cx=partner-pub-6701758236670253:xsqvgh-zggy" + "&q=" + hostparam + searchTerms;
this.curss_LoadURL(URL);
},
curss_TrimString: function (string)
{
// If the incoming string is invalid, or nothing was passed in, return empty
if (!string)
return "";
string = string.replace(/^\s+/, ''); // Remove leading whitespace
string = string.replace(/\s+$/, ''); // Remove trailing whitespace
string = string.replace(/\s+/g, ' ');
return string; // Return the altered value
},
curss_ConvertTermsToURI: function (terms)
{
var termArray = new Array();
termArray = terms.split(" ");
var result = "";
for(var i=0; i<termArray.length; i++)
{
if(i > 0)
result += "+";
result += encodeURIComponent(termArray[i]);
}
return result; // Return the result
},
curss_LoadURL: function (url)
{
if(curss_prefserv.getBoolPref("extensions.cursitesearch.newtab"))
{
const newTab = gBrowser.addTab(url);
gBrowser.selectedTab = newTab;
}
else
window._content.document.location = url;
window.content.focus();
},
curss_KeyHandler: function (event)
{
if(event.keyCode == event.DOM_VK_RETURN)
this.curss_Search();
},
onPrefSubmit: function ()
{
return (true);
},
eraseText: function ()
{
document.getElementById("curss-SearchTerms").value = "";
},
addToTextbox: function (event)
{
var focusedWindow = document.commandDispatcher.focusedWindow;
var searchStr = focusedWindow.getSelection();
document.getElementById("curss-SearchTerms").value = searchStr;
},
trim: function (s)
{
return rtrim(ltrim(s));
},
ltrim: function (s)
{
var l=0;
while(l < s.length && s[l] == ' ')
{ l++; }
return s.substring(l, s.length);
},
rtrim: function (s)
{
var r=s.length -1;
while(r > 0 && s[r] == ' ')
{ r-=1; }
return s.substring(0, r+1);
},
};
window.addEventListener("load", curss.init, false);